package middleware

import (
	"github.com/gin-gonic/gin"
	"apiserver/token"
	"apiserver/handler"
	"apiserver/errno"
	"fmt"
)

//验证用户是否登录
func AuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		ctx, err := token.ParseRequest(c)
		if err != nil {
			handler.SendResponse(c, errno.ErrTokenInvalid, nil)
			c.Abort()
			return
		}
		fmt.Printf("userId:%d", ctx.ID)
		c.Set("userId", ctx.ID)
		c.Next()
	}
}
